package com.news.wemedia.controller.v1.admin;

import com.news.model.common.dtos.ResponseResult;
import com.news.model.wemedia.dtos.SensitiveDto;
import com.news.model.wemedia.pojos.WmSensitive;
import com.news.wemedia.service.SensitiveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

/**
 * 铭感词类，控制层
 */
@RestController
@RequestMapping("/api/v1/sensitive")
public class SensitiveController {

    @Autowired
    private SensitiveService sensitiveService;

    /**
     * 查询名感词列表
     * @param sensitiveDto
     * @return
     */
    @PostMapping("list")
    @Cacheable(value = "sensitive",key = "")
    public ResponseResult getList(@RequestBody SensitiveDto sensitiveDto){
        return sensitiveService.getList(sensitiveDto);
    }

    /**
     * 保存铭感词
     * @param wmSensitive
     * @return
     */
    @PostMapping("/save")
    @CacheEvict(value = "sensitive",key = "",allEntries = true)
    public ResponseResult save(@RequestBody WmSensitive wmSensitive){
        return sensitiveService.saveOne(wmSensitive);
    }

    /**
     * 删除铭感词
     * @param id
     * @return
     */
    @DeleteMapping("/del/{id}")
    @CacheEvict(value = "sensitive",key = "",allEntries = true)
    public ResponseResult del(@PathVariable Integer id){
        return sensitiveService.del(id);
    }

    /**
     * 修改敏感词
     * @param wmSensitive
     * @return
     */
    @PostMapping("/update")
    @CacheEvict(value = "sensitive",key = "",allEntries = true)
    public ResponseResult update(@RequestBody WmSensitive wmSensitive){
        return sensitiveService.updateSensitive(wmSensitive);
    }

}
